﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace AppUnioeste
{
	[Activity (Label = "Calendario")]			
	public class Calendario : Activity
	{
		private ImageButton left;
		private ImageButton right;
		private TextView diaSemana;
		public static SByte diasEvento = 0;

		Dictionary<string, List<string> > dictGroup = new Dictionary<string, List<string> > ();
		List<Dictionary <string, List<string> >> expandableListData =  new List<Dictionary<string, List<string>>>();
		List<string> lstKeys = new List<string> ();
		List<List<string>> dayKeys = new List<List<string>>();

		public String []Days = new String[5]{
			"Segunda-Feira",
			"Terça-feira",
			"Quarta-Feira",
			"Quinta-Feira",
			"Sexta-Feira"
		};

		//adiciona uma expandable list data sem nenhum dado
		public void addExpandableListData(){
			this.expandableListData.Add (new Dictionary<string, List<string>> ());
		}

		//adiciona dados ao dicionario escolhido
		public void AddData(String title, List<String> conteudo, int posicao){
			this.expandableListData.ElementAt (posicao).Add (title, conteudo);
		}


		//seta uma expandable para cada dia
		public void setExpandableListView(Dictionary <string, List<string>> dicionario, List<String> keys){

			var ctlExListBox = FindViewById<ExpandableListView> (Resource.Id.expandableListView1);
			ctlExListBox.SetAdapter (new ExpandableListAdapter (this, dicionario));

			ctlExListBox.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e) {
				var itmGroup = keys [e.GroupPosition];
				var itmChild = dicionario [itmGroup] [e.ChildPosition];

				//Toast.MakeText (this, string.Format ("You Click on Group {0} with child {1}", itmGroup, itmChild), 
				//	ToastLength.Long).Show ();	

			};
		}


		public void iniDataKeys(List<List<String>> keys){

			for (int i = 0; i < 5; i++) {
				
			}
		}

		protected override void OnCreate (Bundle bundle)
		{

			base.OnCreate (bundle);

			// Create your application here
			SetContentView (Resource.Layout.Calendario1);
			/**
			 * SETA OS DADOS DE SEGUNDA A SEXTA - TESTE 
			 * */
			List<String> tipos = new List<string> ();
			tipos.Add ("Palestras");
			tipos.Add ("Minicursos");
			List<String> palestrasSegunda = new List<String> ();
			palestrasSegunda.Add ("xLupa");
			palestrasSegunda.Add ("PlatMult");
			palestrasSegunda.Add ("SigDengue");
			palestrasSegunda.Add ("Guarda Mirin");
			List<String> minicursosSegunda = new List<String> ();
			minicursosSegunda.Add ("Criando um restaurante interativo: curso prático de prototipagem da experiência");
			minicursosSegunda.Add ("Acessibilidade e Inclusão Digital");
			minicursosSegunda.Add ("Visualização de Informação: introdução e influências de IHC");
			addExpandableListData ();
			AddData (tipos.ElementAt (0), palestrasSegunda, 0);
			AddData (tipos.ElementAt (1), minicursosSegunda, 0);
			//addListData (this.expandableListData.ElementAt (0), l1, l);
			setExpandableListView (this.expandableListData.ElementAt(0),tipos);
			this.dayKeys.Add (tipos);
			//my test
			//List<string> listaChaves = new List<string> ();
			/*this.CreateExpendableListDataButton (dictButton,lstKeys);
			var expListView = FindViewById<ExpandableListView> (Resource.Id.expandableListView1);
			expListView.SetAdapter (new ExpandableListAdapterButton (this, dictButton));

			expListView.ChildClick += delegate(object sender, ExpandableListView.ChildClickEventArgs e) {
				var itmGroup = lstKeys [e.GroupPosition];
				var itmChild = dictButton [itmGroup] [e.ChildPosition];

				Toast.MakeText (this, string.Format ("You Click on Group {0} with child {1}", itmGroup, itmChild.Text), 
					ToastLength.Long).Show ();			
			};*/

			initButtons ();


		}

		void initButtons(){
			this.left = FindViewById <ImageButton> (Resource.Id.left);
			this.right = FindViewById <ImageButton> (Resource.Id.right);
			this.left.SetImageResource (Resource.Drawable.left);
			this.left.SetMaxHeight (50);
			this.left.SetMaxWidth (50);
			this.right.SetImageResource (Resource.Drawable.right);
			this.right.SetMaxHeight (50);
			this.right.SetMaxWidth (50);

			this.left.Click += (sender, e) =>{
				this.diaSemana = FindViewById<TextView> (Resource.Id.texto);

				if(--diasEvento<0){
					diasEvento = 4;
				}
				this.diaSemana.Text = Days[diasEvento].ToString();
				//seta os dados conforme os dias do evento
				setExpandableListView (this.expandableListData.ElementAt(diasEvento),this.dayKeys.ElementAt(diasEvento));

			};


			this.right.Click += (sender, e) =>{
				this.diaSemana = FindViewById<TextView> (Resource.Id.texto);
				if(++diasEvento>4){
					diasEvento = 0;
				}
				this.diaSemana.Text = Days[diasEvento].ToString();
				setExpandableListView (this.expandableListData.ElementAt(diasEvento),this.dayKeys.ElementAt(diasEvento));
				//addListData(l1,l);
				//setExpandableListView (this.dictGroup);
			};
		}


		void CreateExpendableListData ()
		{
			for (int iGroup = 1; iGroup <= 3; iGroup++) {
				var lstChild = new List<string> ();
				for (int iChild = 1; iChild <= 3; iChild++) {
					lstChild.Add (string.Format ("Group {0} Child {1}", iGroup, iChild));
				}
				dictGroup.Add (string.Format ("Group {0}", iGroup), lstChild);
			}

			lstKeys = new List<string> (dictGroup.Keys);
		}
			

		/**
		 * Adiciona novos dados ao Dicionario
		 * */
		void addListData (Dictionary <string, List<string>> d, List <String> title, List <String> conteudo)
		{
			for (int iGroup = 0; iGroup < title.Count; iGroup++) {
				//Dictionary <string, List<string>> d = new Dictionary<string, List<string>> ();
				//d.Add (title.ElementAt (iGroup), conteudo);
				//this.expandableListData.Add (d);
				d.Add (title.ElementAt(iGroup), conteudo);
			}
		}

	}
}

